package com.quarters.controller.admin;


import com.quarters.bean.Quarters;
import com.quarters.bean.Repair;
import com.quarters.bean.layuiBean.ResultPage;
import com.quarters.bean.layuiBean.VoPage;
import com.quarters.commen.BaseController;
import com.quarters.util.Respons.ResponseUtil;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * <p>
 * 报修表 前端控制器
 * </p>
 *
 * @author 冯政尚
 * @since 2019-09-02
 */
@Controller
@RequestMapping("admin/repair")
public class RepairController extends BaseController {

    @RequestMapping(value = "repair_add.html",method = RequestMethod.GET)
    public String repair_add(){
        return "admin/repair/repair_add";
    }
    @RequestMapping(value = "repair_edit.html",method = RequestMethod.GET)
    public String repair_edit(){
        return "admin/repair/repair_edit";
    }

    /**
     * @param voPage
     * @return 后台查询
     */
    @RequestMapping(value = "selectMyPage",method = RequestMethod.GET)
    @ResponseBody
    public ResultPage<Repair> selectMyPage(VoPage voPage ){
        return repairService.selectMyPage(voPage );
    }


    /**
     * @param repair
     * @return 添加
     */
    @RequestMapping(value = "saveRepair",method = RequestMethod.POST)
    @ResponseBody
    public Map saveRepair(@RequestBody Repair repair){
        repair.setCreateTime(System.currentTimeMillis());
        if(repairService.save(repair)){
            return ResponseUtil.getSuccessMap();
        }
        return ResponseUtil.getExceptionMap();
    }

    /**
     * @param repair
     * @return 修改
     */
    @RequestMapping(value = "updateByIdRepair",method = RequestMethod.POST)
    @ResponseBody
    public Map updateByIdRepair(@RequestBody Repair repair){
        if(repairService.updateById(repair)){
            return ResponseUtil.getSuccessMap();
        }
        return ResponseUtil.getExceptionMap();
    }

    /**
     * @param repair
     * @return 删除
     */
    @RequestMapping(value = "deleteByIdRepair",method = RequestMethod.POST)
    @ResponseBody
    public Map deleteByIdRepair(@RequestBody Repair repair){
        if(repairService.removeById(repair)){
            return ResponseUtil.getSuccessMap();
        }
        return ResponseUtil.getExceptionMap();
    }




}
